import java.util.ArrayList;
import java.util.List;

public class StringExtractor {
    // 状态枚举（与状态图对应）
    public enum State { INIT, READING, ESCAPING }

    // 提取字符串核心方法
    public static List<String> extractStrings(String source) {
        List<String> result = new ArrayList<>();
        State currentState = State.INIT;
        StringBuilder currentString = new StringBuilder();

        for (char c : source.toCharArray()) {
            switch (currentState) {
                case INIT:
                    if (c == '"') {
                        currentState = State.READING; // 开始提取
                    }
                    break;
                case READING:
                    if (c == '"') {
                        result.add(currentString.toString());
                        currentString.setLength(0);
                        currentState = State.INIT; // 结束提取
                    } else if (c == '\\') {
                        currentState = State.ESCAPING; // 进入转义
                    } else {
                        currentString.append(c); // 记录普通字符
                    }
                    break;
                case ESCAPING:
                    currentString.append(c); // 记录转义字符
                    currentState = State.READING; // 退出转义
                    break;
            }
        }
        return result;
    }

    // 测试方法
    public static void main(String[] args) {
        String testSource = "\"一般学习一门编程语言的时候，基本上第一个程序是输出\\\"Hello World!\\\"\"";
        List<String> extracted = extractStrings(testSource);

        System.out.println("源字符串：" + testSource);
        System.out.println("\n提取结果：");
        for (String s : extracted) {
            System.out.println(s);
        }
    }
}